<%@ page import="org.springframework.web.context.request.SessionScope" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%request.setAttribute("ctx", request.getContextPath());%>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui-v2.9.14/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/jquery-2.1.0.min.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/layui.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/layui_ext/xmSelect/xm-select.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/crypto-js.js"></script>
    <title>用户列表</title>
</head>
<body>
<form class="layui-form layui-row layui-col-space16">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">日期范围</label>
            <div class="layui-inline" id="ID-laydate-range">
                <div class="layui-input-inline">
                    <input type="text" name="startTime" autocomplete="off" id="ID-laydate-start-date" class="layui-input" placeholder="开始日期">
                </div>
                <div class="layui-form-mid">-</div>
                <div class="layui-input-inline">
                    <input type="text" name="endTime" autocomplete="off" id="ID-laydate-end-date" class="layui-input" placeholder="结束日期">
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所属组</label>
        <div class="layui-input-block">
            <select name="groupId">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-btn-container layui-col-xs12">
        <button class="layui-btn" lay-submit lay-filter="demo-table-search">Search</button>
        <button type="reset" class="layui-btn layui-btn-primary">Clear</button>
    </div>
</form>
<button class="layui-btn" lay-on="e1">导出报表</button>
<span id="totalNum"></span><span id="time"></span>
<table class="layui-hide" id="ID-table-demo-search"></table>


<script>
    layui.use(function(){
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;

        var util = layui.util;
        //  2.9+ 版本可省略 attr 参数，默认读取 lay-on
        util.on({
            e1: function(){
                location.href="/order/outreport.do";
            },
        });

        $.get("/order/listgroup.do",{type:'所属组'},function (res) {
            let data=res.data;
            for (let i = 0; i < data.length; i++) {
                $("[name=groupId]").append("<option value='"+data[i].code+"'>"+data[i].name+"</option>")
            }
            form.render("select")
        })
        // 创建表格实例
        table.render({
            elem: '#ID-table-demo-search',
            url: '/order/report.do', // 此处为静态模拟数据，实际使用时需换成真实接口

            parseData:function (res) {
                $("#totalNum").text("共查询到"+res.data.count+"条")
                $("#time").text("共耗时"+res.data.time+"秒")
                return{
                    code:res.code,
                    data:res.data.orderReportList,

                }
            },
            cols: [[
                {field:'username', title: '客户姓名', width:80},
                {field:'groupName', title: '所属组', width:80, sort: true},
                {field:'totalNum', title: '创建工单数', width:80},
                {field:'doingNum', title: '当前未解决的工单数', width:80},
                {field:'okNum', title: '解决工单数', width:80},
                {field:'rateNum', title: '关闭工单数', width:80},
                {field:'avgminuntes', title: '平均解决时间', width:80},
            ]],
            page: true,
            height: 310
        });
        // 日期
        laydate.render({
            elem: '#ID-laydate-range',
            range: ['#ID-laydate-start-date', '#ID-laydate-end-date']
        });
        // 搜索提交
        form.on('submit(demo-table-search)', function(data){
            var field = data.field; // 获得表单字段
            // 执行搜索重载
            table.reload('ID-table-demo-search', {
                page: {
                    curr: 1 // 重新从第 1 页开始
                },
                where: field // 搜索的字段
            });
            layer.msg('搜索成功<br>此处为静态模拟数据，实际使用时换成真实接口即可');
            return false; // 阻止默认 form 跳转
        });
    });
</script>

</body>
</html>